<!--
* @author luguoxiang
* @date 2021-09-07
* 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <t-dialog v-model:visible="visible" v-bind="config" class="edit-container" @closed="close">
    <template v-for="(x, key) in $slots" #[key]="scope">
      <slot :name="key" v-bind="scope" :data="data"></slot>
    </template>
  </t-dialog>
</template>

<script lang="ts" setup="EditContainerModal">
import { computed, ref, useAttrs } from 'vue';
import { EditContainerProps } from './types';

export declare interface Props extends EditContainerProps {
  /**
   * 宽度
   */
  width?: string | number;
}

const emits = defineEmits(['open', 'close']);
const props = defineProps<Props>();

const visible = ref<boolean>(false);
const data = ref<any>();
const config = computed(() => {
  return {
    ...props,
    width: props.width ?? 1200,
    ...useAttrs(),
  };
});

function open(params: any) {
  visible.value = true;
  data.value = params;
  emits('open', params);
}

function close() {
  visible.value = false;
  data.value = null;
  emits('close');
}

defineExpose({
  open,
  close,
});
</script>
